package selcoursesys.action;

import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.ServletActionContext;
import selcoursesys.entity.CourseEntity;
import selcoursesys.entity.CourseInfo;
import selcoursesys.entity.SelectionEntity;
import selcoursesys.service.CourseService;
import selcoursesys.service.SelectionService;
import selcoursesys.service.impl.CourseServiceImpl;
import selcoursesys.service.impl.SelectionServiceImpl;
import javax.servlet.http.HttpServletRequest;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
/**
 * Created by Lpbdz on 2017/4/11.
 */
public class elevInfo {
    public static void showElvInfo(SelectionEntity selectionEntity, List<CourseEntity> list) {
        //返回jsp页面的数据
        List<CourseInfo> courseInfos = new LinkedList<CourseInfo>();

        CourseService courseService = new CourseServiceImpl();
        CourseEntity courseEntity = new CourseEntity();
        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            CourseEntity courseEntity1 = (CourseEntity) iterator.next();
            courseEntity.setCourseid(courseEntity1.getCourseid());
            CourseEntity courseEntity2 = courseService.queryCourseId(courseEntity);
            System.out.println(courseEntity1.getCourseid() + " " + courseEntity1.getCoursename() + " " +
                    courseEntity1.getCredit() + " " + courseEntity2.getTeacherEntity().getTname());
            SelectionService checkexit = new SelectionServiceImpl();
            if (checkexit.checkSelectionExit(selectionEntity.getStuid(), courseEntity1.getCourseid()) == true) {
                courseInfos.add(new CourseInfo(courseEntity1.getCoursename(), courseEntity1.getCredit(), courseEntity1.getCourseid(),
                        courseEntity2.getTeacherEntity().getTname(), "已选",selectionEntity.getStuid()));
            } else {
                courseInfos.add(new CourseInfo(courseEntity1.getCoursename(), courseEntity1.getCredit(), courseEntity1.getCourseid(),
                        courseEntity2.getTeacherEntity().getTname(), "未选",selectionEntity.getStuid()));
            }
            ActionContext.getContext().put("elecourseInfo", courseInfos);
        }
    }
}
